﻿Public Class frm_list_smp
    Sub cmb_group_search()
        cmb_group.Items.Add("No Pendaftaran")
        cmb_group.Items.Add("Nama Pendaftar")
        cmb_group.Items.Add("No Uan")
    End Sub
    Sub BuatTable()
        With lv_smp.Columns
            .Clear()
            .Add("No", 45, HorizontalAlignment.Right) '0
            .Add("Tanggal Pendaftaran", 140, HorizontalAlignment.Center) '1
            .Add("Asal Pendaftar", 140, HorizontalAlignment.Center) '2
            .Add("Asal Sekolah", 150, HorizontalAlignment.Center) '3
            .Add("Jenis Kelamin", 90, HorizontalAlignment.Center) '4
            .Add("No. Pendaftaran", 145, HorizontalAlignment.Center) '5
            .Add("Nama", 140, HorizontalAlignment.Left) '6
            .Add("B. Indo", 50, HorizontalAlignment.Right) '7
            .Add("Matematika", 50, HorizontalAlignment.Right) '8
            .Add("IPA", 50, HorizontalAlignment.Right) '9
            .Add("Total Nilai", 80, HorizontalAlignment.Right) '10
            .Add("Pilihan 1", 190, HorizontalAlignment.Left) '11
            .Add("Pilihan 2", 190, HorizontalAlignment.Left) '12
        End With
        lv_smp.GridLines = True
        lv_smp.View = View.Details
        lv_smp.FullRowSelect = True
    End Sub
    Private Sub frm_list_smp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cmb_group_search()
        BuatTable()
        cmb_group.SelectedIndex = 0
        DB.FlushCache()
        DB.Selects("*")
        DB.From("tbl_pendaftaran_smp")

        Connection.ExecuteToDataReader(DB.GetQueryString)

        If Connection.Read.HasRows Then

            With Connection.Read
                Dim numb As Integer

                numb = 0
                While .Read
                    Dim pilihan_2 As String
                    Dim asal_pendaftar As String
                    numb = numb + 1
                    lv_smp.Items.Add(numb) '0
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(1).ToString.Split(" ")(0)) '1
                    If .Item(2).ToString = 0 Then
                        asal_pendaftar = "Dalam Kota"
                    Else
                        asal_pendaftar = "Luar Kota"
                    End If
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(asal_pendaftar) '2
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(10).ToString) '3
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(7).ToString) '4
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(3).ToString) '5
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(6).ToString) '6
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(FormatNumber(.Item(11).ToString, 2)) '7
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(FormatNumber(.Item(12).ToString, 2)) '8
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(FormatNumber(.Item(13).ToString, 2)) '9
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(FormatNumber(.Item(14).ToString, 2)) '10
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(ListSekolah.getNama(.Item(16).ToString)) '11
                    If .Item(17).ToString = .Item(16).ToString Then
                        pilihan_2 = "Tidak Memilih"
                    Else
                        pilihan_2 = ListSekolah.getNama(.Item(17).ToString)
                    End If
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(pilihan_2) '12
                End While

            End With

        End If

    End Sub

    Private Sub lv_smp_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lv_smp.DoubleClick
        Dim no_unique
        If lv_smp.Items.Count > 0 Then
            'frm_smp_edit.lblid.Text = ListView1.SelectedItems(0).Text
            no_unique = lv_smp.SelectedItems(0).SubItems(5).Text
            frm_smp_edit.MdiParent = frm_main
            frm_smp_edit.WindowState = FormWindowState.Maximized
            frm_smp_edit.Show()
            frm_smp_edit.InitData(no_unique)
            frm_smp_edit.Focus()
        End If
        'Me.Dispose()
        'Me.Close()
    End Sub
    Private Sub cmd_search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_search.Click

        Dim group_filter As String
        group_filter = cmb_group.SelectedIndex
        Select Case group_filter
            Case "0"
                group_filter = "no_pendaftaran"
            Case "1"
                group_filter = "nama_pendaftar"
            Case "2"
                group_filter = "no_uan"
        End Select

        DB.FlushCache()
        DB.Selects("*")
        DB.From("tbl_pendaftaran_smp")
        DB.Where("WHERE " & group_filter & " LIKE '%" & txt_search.Text & "%'")

        Connection.ExecuteToDataReader(DB.GetQueryString)
        lv_smp.Items.Clear()
        If Connection.Read.HasRows Then

            With Connection.Read
                Dim numb As Integer
                numb = 0
                While .Read
                    numb = numb + 1
                    lv_smp.Items.Add(numb)
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(1).ToString.Split(" ")(0))
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(2).ToString)
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(10).ToString)
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(7).ToString)
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(3).ToString)
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(6).ToString)
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(FormatNumber(.Item(11).ToString, 2))
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(FormatNumber(.Item(13).ToString, 2))
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(FormatNumber(.Item(14).ToString, 2))
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(FormatNumber(.Item(15).ToString, 2))
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(17).ToString)
                    lv_smp.Items.Item(lv_smp.Items.Count - 1).SubItems.Add(.Item(18).ToString)
                End While

            End With

        End If
    End Sub

    Private Sub lv_smp_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lv_smp.SelectedIndexChanged

    End Sub
End Class